package com.yc.txx.biz;

import com.yc.txx.entity.User;
import com.yc.txx.mapper.UserMapper;
import com.yc.txx.util.MyBatisHelper;
import org.apache.ibatis.session.SqlSession;

public class UserBiz {

    public User login(String name, String pwd) throws BizExcpetion {
        if (name == null || name.trim().isEmpty()) {
            throw new BizExcpetion("请输入用户名!");
        }
        if (pwd == null || pwd.trim().isEmpty()) {
            throw new BizExcpetion("请输入密码!");
        }
        User user;
        try (final SqlSession session = MyBatisHelper.getSession();) {
            final UserMapper mapper = session.getMapper(UserMapper.class);
            user = mapper.selectForLogin(name, pwd);
        } catch (Exception e){
            e.printStackTrace();
            throw new BizExcpetion("业务繁忙,稍后再试!",e);
        }
        if(user == null){
            throw new BizExcpetion("用户名或密码错误!");
        }
        return user;
    }
}
